import {
    companySupplierRevoke,
    insuranceWesureInfo,
    deleteInsureEnterprise
} from '../../api/insurance'
import user from '../../../utils/user.js'
import {
    toast,
    confirm
} from '../../../utils/util'
Page({
    data: {
        type: '',
        title: '',
        msg: '',
        companyId: '',
        addTimeList: [],
        isAll: false,
        id: '',
        insureCompanyType: '',
        mediaList: [],
        isadmin: 0
    },
    onShow() {
        user.waitLogin().then((res) => {
            this.setData({
                isadmin: user.isAdmin
            })
        })
    },
    onLoad: function (options) {
        console.log(options, '111')
        this.setData({
            id: options.id
        })
        if (Number(options.all)) {
            this.setData({
                type: 'success',
                title: '您已开通24H投保',
                msg: '',
                isAll: true,
            })
            return
        }
        insuranceWesureInfo({
            id: options.id
        }).then(res => {
            if (res.wesureTimeAddList) {
                res.wesureTimeAddList.forEach((item, index) => {
                    let ind = index += 1
                    index -= 1
                    res.wesureTimeAddList[index].whatDay = '第' + ind + '次投保时间'
                })
            }

            console.log(res.wesureInfo.auditStatus, 'wesureInfo')
            this.setData({
                addTimeList: res,
                wesureTimeDayShiftAudit: res.wesureInfo.wesureTimeDayShiftAudit,
                wesureTimeNightShiftAudit: res.wesureInfo.wesureTimeNightShiftAudit,
                type: res.wesureInfo.auditStatus === 0 || res.wesureInfo.auditStatus === 3 ? 'waiting' : res.wesureInfo.auditStatus === 1 ? 'success' : res.wesureInfo.auditStatus === 2 ? 'warn' : 'info',
                title: res.wesureInfo.auditStatus === 0 || res.wesureInfo.auditStatus === 3 ? '审核中' : res.wesureInfo.auditStatus === 1 ? '已通过' : res.wesureInfo.auditStatus === 2 ? '已驳回' : '暂无信息',
                msg: res.wesureInfo.auditStatus === 0 || res.wesureInfo.auditStatus === 3 ? '该派遣单位将在10小时内完成审核' : res.wesureInfo.auditStatus === 1 ? '审核已通过，您可以在创建项目时选择该企业' : res.wesureInfo.auditStatus === 2 ? '该派遣单位审核已驳回，请根据驳回理由修改' : '暂无更多详细信息',
                companyId: options.id,
                insureCompanyType: user.insureCompanyType,
                mediaList: res.wesureInfo.wesureFileDetailsList
            }, () => {
                console.log(this.data.addTimeList, 'addTimeList')
            })
        })
    },
    noGoIndex() {
        wx.navigateBack({
            delta: 3
        })
    },
    noGoAgain() {
        wx.navigateBack({
            delta: 2
        })
    },
    // 撤销更改
    revoke() {
        confirm('确认撤销吗？').then(() => {
            companySupplierRevoke({
                id: this.data.companyId,
                insureCompanyType: user.insureCompanyType
            })
            wx.navigateBack({
                delta: 1,
            })
            toast('撤销成功')
        })
    },
    // 删除投保企业
    dele() {
        confirm(this.data.insureCompanyType === 'insure001_wesure' ? '确认删除' : '确认撤销').then(() => {
            deleteInsureEnterprise({
                id: this.data.id,
                insureCompanyType: user.insureCompanyType
            }).then((res) => {
                wx.navigateBack()
                toast('删除成功')
            })
        })
    },
    // 点击图片放大
    onPreview(event) {
        const {
            url
        } = event.currentTarget.dataset
        wx.previewImage({
            urls: [url]
        })
    },
    onPlay(event) {
        console.log(event.currentTarget.id)
        // 获取 video 上下文 videoContext 对象
        this.videoContext = wx.createVideoContext(event.currentTarget.id, this)
        // 进入全屏状态
        this.videoContext.requestFullScreen()
        return 0
    },

})